/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package net.sf.l2j.gameserver.custom.achievements;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import net.sf.l2j.gameserver.custom.achievements.data.ChampionAchievement;
import net.sf.l2j.gameserver.custom.achievements.data.TycoonAchievement;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;

/**
 * @author Anarchy
 *
 */
public class AchievementsManager
{
	private static final Logger _log = Logger.getLogger(AchievementsManager.class.getName());
	
	private List<IAchievement> _achievements;
	
	public static AchievementsManager getInstance()
	{
		return SingletonHolder._instance;
	}
	
	protected AchievementsManager()
	{
		_achievements = new ArrayList<>();
		
		_achievements.add(new TycoonAchievement());
		_achievements.add(new ChampionAchievement());
		
		_log.info("Loaded "+_achievements.size()+" achievements.");
	}
	
	public String parseAchievements(L2PcInstance p)
	{
		String s = "";
		
		for (IAchievement a : _achievements)
		{
			if (p.getCompletedAchievements() != null && p.getCompletedAchievements().contains(a.getName()))
			{
				s += "Name: <font color=\"LEVEL\">"+a.getName()+"</font> Status: <font color=\"LEVEL\">COMPLETED</font><br1>";
			}
			else
			{
				if (a.meetsRequirements(p))
				{
					s += "Name: <font color=\"LEVEL\">"+a.getName()+"</font> Status: <font color=\"LEVEL\">COMPLETED</font> <a action=\"bypass -h bp_getReward "+a.getName()+"\">Get reward.</a><br1>";
				}
				else
				{
					s += "Name: <font color=\"LEVEL\">"+a.getName()+"</font> Status: <font color=\"LEVEL\">NOT-COMPLETED</font><br1>";
				}
			}
		}
		
		return s;
	}
	
	public List<IAchievement> getAchievements()
	{
		return _achievements;
	}
	
	private static class SingletonHolder
	{
		protected static final AchievementsManager _instance = new AchievementsManager();
	}
}
